import { Injectable, Inject } from '@angular/core';
import { TokenService, ITokenService, DA_SERVICE_TOKEN } from '@delon/auth';
import { Router, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivate } from '@angular/router';

@Injectable()
export class MyAuthGuardService implements CanActivate {

  constructor(private router: Router, @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService) { }

  canActivate(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    var tokenService = this.tokenService.get();
    if(!tokenService.token)
    {        
      this.router.navigate(['/passport/login'], { queryParams: { returnUrl: state.url }});
      return false;  
    }

    return true;
  }

}
